package net.elive.server;

import java.net.InetAddress;

import net.elive.utils.LogUtils;

import org.apache.commons.logging.Log;

/**
 * 节点管理类
 * 
 * @author Administrator
 * 
 */
public class NodeManage {

	private Log log = LogUtils.getLog(NodeManage.class);

	/**
	 * 根据sessionId删除在线用户节点
	 * 
	 * @param sessionId
	 */
	public void removeNode(int sessionId) {
		if (sessionId > 0) {
			Config.onlineNode.remove(sessionId);
		}
	}

	/**
	 * 根据sessionId获取在线用户节点
	 * 
	 * @param sessionId
	 */
	public Node getNodeBySession(int sessionId) {
		if (sessionId > 0) {
			Node node = Config.onlineNode.get(sessionId);
			if (node != null) {
				return node;
			} else {
				return null;
			}
		} else {
			return null;
		}
	}

	/**
	 * 添加节点到服务器中
	 * 
	 * @param nodeIp
	 *            节点ip
	 * @param sessionId
	 *            用户session
	 * @param nodeType
	 *            节点类型
	 * @param routePort
	 *            路由端口
	 * @param dbServer
	 *            服务器端口
	 * @param assistPort
	 *            协服务器端口
	 */
	public void addNode(InetAddress nodeIp, int sessionId, short nodeType,
			int routePort, int dbServerPort, int assistPort) {
		Node node = new Node(nodeIp, sessionId, nodeType, routePort,
				dbServerPort, assistPort);
		Config.onlineNode.put(sessionId, node);
		log.info(">>>>>>添加节点>>>节点IP：" + nodeIp + "登录session:" + sessionId
				+ "节点类型:" + nodeType + "路由端口:" + routePort+ "服务器端口:"
				+ dbServerPort+ "协服务器端口:"+assistPort); 
	}
}
